//
//  WJYEmailViewController.m
//  WWLNetease
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 Echo.Jobs. All rights reserved.
//

#import "WJYEmailViewController.h"
#define Kheight [[UIScreen mainScreen]bounds].size.height / 667
@interface WJYEmailViewController ()<UITextViewDelegate, UITextFieldDelegate>

@property(nonatomic, retain) UILabel *introduceLabel;

@property(nonatomic, retain) UITextField *contactTextField;

@property(nonatomic, retain) UITextField *passTextField;

@property(nonatomic, retain) UITextView *suggestionTextView;

@end

@implementation WJYEmailViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.886 green:0.227 blue:0.255 alpha:1];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 60 * Kheight, 0, 120 * Kheight, 30 * Kheight)];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"意见反馈";
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:20 * Kheight];
    self.navigationItem.titleView = titleLabel;

    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backToHomePage:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];

    [self creatSubViews];
}

- (void)creatSubViews
{
    self.introduceLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * Kheight, 69, self.view.frame.size.width - 20 * Kheight, 50 * Kheight)];
    self.introduceLabel.numberOfLines = 2;
    self.introduceLabel.font = [UIFont systemFontOfSize:17 * Kheight];
    self.introduceLabel.text = @"亲爱的用户: 欢迎提需求或建议, 我们的进步离不开您的反馈!";
    self.introduceLabel.textColor = [UIColor blackColor];
    [self.view addSubview:self.introduceLabel];

    
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(self.introduceLabel.frame.origin.x, self.introduceLabel.frame.size.height + self.introduceLabel.frame.origin.y + 5 * Kheight, self.introduceLabel.frame.size.width - 5 * Kheight, self.view.frame.size.height / 16)];
    backgroundView.backgroundColor = [UIColor redColor];
    backgroundView.layer.cornerRadius = 8 * Kheight;
    backgroundView.layer.borderWidth = 0.5 * Kheight;
    backgroundView.layer.borderColor = [[UIColor colorWithRed:0.651 green:0.651 blue:0.651 alpha:1] CGColor];
    backgroundView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backgroundView];

    
    self.contactTextField = [[UITextField alloc] initWithFrame:CGRectMake(8 * Kheight, 5 * Kheight, backgroundView.frame.size.width - 16 * Kheight, backgroundView.frame.size.height - 10 * Kheight)];
    self.contactTextField.delegate = self;
    self.contactTextField.font = [UIFont systemFontOfSize:17 * Kheight];
    self.contactTextField.placeholder = @" 联系方式(Email或者QQ号)";
    self.contactTextField.keyboardType = UIKeyboardTypeEmailAddress;
    self.contactTextField.clearButtonMode = UITextFieldViewModeAlways;
    [backgroundView addSubview:self.contactTextField];

    
    UIView *suggestionBackView = [[UIView alloc] initWithFrame:CGRectMake(backgroundView.frame.origin.x, backgroundView.frame.origin.y + backgroundView.frame.size.height + 15 * Kheight, backgroundView.frame.size.width, self.view.frame.size.height / 3)];
    suggestionBackView.layer.cornerRadius = 8 * Kheight;
    suggestionBackView.layer.borderWidth = 0.5 * Kheight;
    suggestionBackView.layer.borderColor = [[UIColor colorWithRed:0.651 green:0.651 blue:0.651 alpha:1] CGColor];
    suggestionBackView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:suggestionBackView];

    
    self.suggestionTextView = [[UITextView alloc] initWithFrame:CGRectMake(8 * Kheight, 5 * Kheight, suggestionBackView.frame.size.width - 16 * Kheight, suggestionBackView.frame.size.height - 10 * Kheight)];
    self.suggestionTextView.delegate = self;
    self.suggestionTextView.backgroundColor = [UIColor whiteColor];
    self.suggestionTextView.font = [UIFont systemFontOfSize:15 * Kheight];
    [suggestionBackView addSubview:self.suggestionTextView];

    
    //提交按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(self.view.center.x - 100 * Kheight, suggestionBackView.frame.size.height + suggestionBackView.frame.origin.y + 25 * Kheight, 200 * Kheight, 50 * Kheight);
    [button setTitle:@"提交意见" forState:UIControlStateNormal];
    [button setTintColor:[UIColor whiteColor]];
    button.layer.cornerRadius = 8 * Kheight;
    button.layer.masksToBounds = YES;
    [button addTarget:self action:@selector(commitText:) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont boldSystemFontOfSize:23 * Kheight];
    button.backgroundColor = [UIColor colorWithRed:0.886 green:0.227 blue:0.255 alpha:1];
    [self.view addSubview:button];
    
    //给键盘上方添加按钮
    UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
    topView.backgroundColor = [UIColor colorWithRed:0.651 green:0.651 blue:0.651 alpha:1];
    UIBarButtonItem * btnSpace1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem * btnSpace2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(dismissKeyBoard)];
    NSArray * buttonsArray = [NSArray arrayWithObjects: btnSpace1, btnSpace2, doneButton, nil];

    
    [topView setItems:buttonsArray];
    [self.suggestionTextView setInputAccessoryView:topView];

}

- (void)commitText:(UIButton *)button
{
    if (self.suggestionTextView.text.length == 0 || self.contactTextField.text.length == 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"联系方式或反馈内容不能为空" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [self.view addSubview:alert];
        [alert show];

    }else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"谢谢您的意见, 我们会积极采纳" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [self.view addSubview:alert];
        [alert show];

    }
}

#pragma mark 键盘上方的收键盘按钮
-(void)dismissKeyBoard
{
    [self.suggestionTextView resignFirstResponder];
}

#pragma mark 返回按钮
- (void)backToHomePage:(UIBarButtonItem *)barButtonItem
{
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //失去第一响应者
    [textField resignFirstResponder];
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
